package com.greate.community.service.master;

import com.alibaba.fastjson.JSON;
import com.greate.community.dao.admin.IndexAdminMapper;
import com.greate.community.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class IndexAdminService  {
    @Autowired
    DataService dataService;

    @Autowired
    IndexAdminMapper indexAdminMapper;
    /**
     * 获得管理员界面的一些基础信息
     * @return
     */
    @Transactional
    public Object getIndexBaseInfo() {
        //用户数
        int userNum=indexAdminMapper.getUserNum();
        //总帖子数
        int discussNum=indexAdminMapper.getDiscussNum();
        //总评论数
        int commentNum=indexAdminMapper.getCommentNum();
        //每个分区的数量信息
        List<Map<Integer,String>> sectionNum=indexAdminMapper.getSectionNum();
        //uv和Dav信息 最近一周的信息
            Date date = new Date();//当前时间
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            //获得一周前当前的时间
            calendar.add(Calendar.DAY_OF_MONTH,-7);
        long uv = dataService.calculateUV(calendar.getTime(), date);

        long dau = dataService.calculateDAU(calendar.getTime(), date);

        HashMap<Object, Object> indexInfo = new HashMap<>();
        indexInfo.put("sectionNum",sectionNum);
        indexInfo.put("userNum",userNum);
        indexInfo.put("discussNum",discussNum);
        indexInfo.put("commentNum",commentNum);
        indexInfo.put("dau",dau);
        indexInfo.put("uv",uv);
        return indexInfo;
    }
}
